class ScoreList extends eui.Component implements eui.UIComponent {
	public constructor() {
		super();
		// this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addEvents , this);
		// this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removeEvents, this);
		this.addEventListener(eui.UIEvent.ADDED_TO_STAGE,this.addEvents , this);
		this.addEventListener(eui.UIEvent.REMOVED_FROM_STAGE, this.removeEvents, this);
	}
	private list: eui.List;
	private closeBtn: eui.Button;

	private scoreList: ScoreList;

	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}

	protected createChildren(): void {
		super.createChildren();
		this.skinName = "resource/skin/ScoreListskin.exml";
	}

	protected childrenCreated(): void {
		super.childrenCreated();
	}

	private addEvents(): void {
		this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.close, this);
		this.list.addEventListener(eui.ItemTapEvent.ITEM_TAP, this.listItemTap, this);
		App.event.addEventListener(GameEvent.RENDER_LIST, this.renderList, this);
		SocketIo.getInstance().request("reqList", 3);
	}

	private removeEvents(): void {
		this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.removeEvents, this);
		this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.close, this);
		this.list.removeEventListener(eui.ItemTapEvent.ITEM_TAP, this.listItemTap, this);
		App.event.removeEventListener(GameEvent.RENDER_LIST, this.renderList, this);
	}

	private renderList(evt: GameEvent): void {
		let resp = evt.data;
		this.list.dataProvider = new eui.ArrayCollection(resp.data);
	}

	private listItemTap(e: eui.ItemTapEvent): void {
		let data = e.itemIndex;
	}

	private close(): void {
		if (this.parent) {
			this.parent.removeChild(this);
		}
	}

	public dispose(): void {
		this.removeEvents();
	}

}